<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2018/6/13
 * Time: 10:40
 */
namespace app\api\controller;
use think\Controller;
use think\Db;

class  Base extends Controller {
    protected $_error;
    protected $_header;//用户的请求头信息
    protected $otherLogin  = '您的账号已在其他设备登录';
    protected $frost = '您的账号已注销或被冻结';
    protected $del = '您的账号已被删除';
    // 抽烟习惯
    protected $smoke = [
        '1' => '从不吸烟',
        '2' => '偶尔一根',
        '3' => '戒烟中',
        '4' => '老烟枪'
    ];
    // 饮酒习惯
    protected $liquor = [
        '1' => '滴酒不沾',
        '2' => '偶尔小酌',
        '3' => '社交应酬',
        '4' => '品酒达人',
        '5' => '千杯不醉',
        '6' => '一杯脸红'
    ];
    
    // 构造函数
    public function __construct(){
        // 如果配置项为空 则直接返回

    }

    /**
     * 验证唯一——单点登录
     * user_id，time，salt，value
     * @return string
     */
    public  function checkAll($uid,$time,$value,$reqKey){
        if($uid == 0){
            return 111;
        }else{
            $user = Db::table('up_u_user')->where('user_id',$uid)->find();
            if($user['user_status'] == 3){ // 冻结
                return 110;
            }
            if($user['user_status'] == 4){ // 删除
                return 2111;
            }
            $token = $user['user_token'];
            $appId = "A6070308312682";
            $appkey = "9AF807B0-BE12-F521-6998-6D57B0CCE8BB";
            $myreqKey = md5($appId . 'XW' . $appkey . 'XW' . $time);
            $myvalue = md5($uid . 'XW' . $token . 'XW' . $time);
            if($myvalue != $value || $myreqKey != $reqKey){
                return 112;
            }else{
                return 111;
            }
        }
    }
    
    public  function killUpdate(){//$uid,$time,$value
        $today = date('Y-m-d');
        Db::table('up_goods')
            ->where('g_kill_end','<',$today)
            ->where('g_prcie_kill','>',0)
            ->where('g_status',1)
            ->update(['g_prcie_kill'=>0]);
    }
    /**
     * 云之讯发送短信
     * @param $phone
     * @param $num
     * @return mixed
     */
    public function duaxin($phone,$num){
//        header("Content-type: text/html; charset=utf-8");
        $body_json = array(
            'sid'=>'05b0c3cc6133227764acc0e1b6ea21ad',
            'token'=>'42c56907ae16aa3615c3945e72e26249',
            'appid'=>'414eed7c02e146598852492fa626204d',
            'templateid'=>'400297',
            'param'=>$num,
            'mobile'=>$phone,
            'uid'=>'',
        );
        $body = json_encode($body_json);
        $header = array(
            'Accept:application/json',
            'Content-Type:application/json;charset=utf-8',
        );
        $url = 'https://open.ucpaas.com/ol/sms/sendsms';
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch,CURLOPT_POST,1);
        curl_setopt($ch,CURLOPT_POSTFIELDS,$body);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        $result = curl_exec($ch);
        curl_close($ch);
        $res = json_decode($result,true);
        return $res;
    }
    /**
     * param $tmp
     * param $name
     * param $size
     * 上传图片
     */
//    public function uploadFile($tmp,$name,$size)
    public function uploadFile()
    {
        $tmp = $_FILES['image']['tmp_name'];
        $name = $_FILES['image']['name'];
        $size = $_FILES['image']['size'];
        if($size > 1024*1024*5){
            return json_encode(['status'=>0,'msg'=>"图片不得超过5M！"]);
        }
        $imgarray = array('jpg','jpeg','png');
        $dir = $_SERVER['DOCUMENT_ROOT'];
        $url =  "http://".$_SERVER['HTTP_HOST'];
        if($tmp){
            //=======重命名=====
            $rand = date('YmdHis').rand(100000,999999);
            $exe = explode('.',$name);
            $exe = end($exe);
//            if(!in_array($exe,$imgarray)){
//                return json_encode(['status'=>0,'msg'=>'图片格式不支持']);
//            }
//            $newName = $rand . '.' .$exe;
            $newName = $rand . '.png';
            //=======================
            if(move_uploaded_file($tmp,"{$dir}/image/{$newName}")){
                $imgUrl = "{$url}/image/{$newName}";
                if($size > 1024*1024*2){
                    $this->image_png_size_add("{$dir}/image/{$newName}","{$dir}/image/{$newName}");
                }
                return json_encode(['status'=>200,'msg'=>$imgUrl]);
            }else{
                return json_encode(['status'=>0,'msg'=>'图片保存失败']);
            }
        }else{
            return json_encode(['status'=>0,'msg'=>"上传一张图！"]);
        }
    }

    /**
     * 压缩图片
     * @param $imgsrc:原图片地址（完整的图片路径）
     * @param $imgdst:压缩后的图片地址，也是完整的
     */
    function image_png_size_add($imgsrc,$imgdst){
        list($width,$height,$type)=getimagesize($imgsrc);
        switch($type){
            case 1:
                break;
            case 2:
                header('Content-Type:image/jpeg');
                $image = imagecreatefromjpeg($imgsrc);
                imagejpeg($image, $imgdst,20);
                imagedestroy($image);
                break;
            case 3:
                header('Content-Type:image/png');
                $image = imagecreatefrompng($imgsrc);
                imagejpeg($image, $imgdst,20);
                imagedestroy($image);
                break;
        }
    }

    /**
     * formatTime 时间格式化
     * @param $time 时间戳
     * @return string
     */
    public function formatTime($time) {
        $now_time = time();
        $t = $now_time - $time;
        $yea = (int) ($t / (86400 * 30 * 12));
        if ($yea >= 1) {
            return $yea.'年前';
        }
        $mon = (int) ($t / (86400 * 30));
        if ($mon >= 1) {
            return '一个月前';
        }
        $day = (int) ($t / 86400);
        if ($day >= 1) {
            return $day . '天前';
        }
        $h = (int) ($t / 3600);
        if ($h >= 1) {
            return $h . '小时前';
        }
        $min = (int)($t / 60);
        if ($min >= 1) {
            return $min . '分钟前';
        }
        return '刚刚';
    }

    /**
     * 获取任意长度的随机字符串
     * @param $length
     * @return string
     */
//    function getRandChar($length)
//    {
//        $chars = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
//            'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
//            't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D',
//            'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
//            'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
//            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
//        $char_txt = '';
//        for ($i = 0; $i < $length; $i++) {
//            $char_txt .= $chars[array_rand($chars)];
//        }
//        return $char_txt;
//    }

    /**
     * 验证码
     * @param $length
     * @return string
     */
    function getCodeChar($length)
    {
        $chars = array(
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
        $char_txt = '';
        for ($i = 0; $i < $length; $i++) {
            $char_txt .= $chars[array_rand($chars)];
        }
        return $char_txt;
    }
    public function getAcount()
    {
        //==========base里放到===============
        $zimu = range('a','z');
        $one = rand(0,25);
        $two = rand(0,25);
        $thr = rand(0,25);
        $four = rand(0,25);
        $zimu2 = $zimu[$one].$zimu[$two].$zimu[$thr].$zimu[$four];
        $num = rand(100000,999999);
        return $zimu2.$num;
        //=========================
    }
    
    /**
     * 根据生日计算星座
     * @param $birthday   生日   xxxx-xx-xx
     * @return string
     */
    public function get_constellation($birthday){
        $his = ' 00:00:00';
        $y = substr($birthday, 0, 4) . '-';
        $userTime = strtotime($birthday . $his);
        // 水瓶座
        $januaryS   = strtotime($y . '01-20' . $his);
        $januaryE   = strtotime($y . '02-18' . $his);
        // 双鱼座
        $februaryS  = strtotime($y . '02-19' . $his);
        $februaryE  = strtotime($y . '03-20' . $his);
        // 白羊座
        $marchS     = strtotime($y . '03-21' . $his);
        $marchE     = strtotime($y . '04-19' . $his);
        // 金牛座
        $aprilS     = strtotime($y . '04-20' . $his);
        $aprilE     = strtotime($y . '05-20' . $his);
        // 双子座
        $mayS       = strtotime($y . '05-21' . $his);
        $mayE       = strtotime($y . '06-21' . $his);
        // 巨蟹座
        $juneS      = strtotime($y . '06-22' . $his);
        $juneE      = strtotime($y . '07-22' . $his);
        // 狮子座
        $julyS      = strtotime($y . '07-23' . $his);
        $julyE      = strtotime($y . '08-22' . $his);
        // 处女座
        $augustS    = strtotime($y . '08-23' . $his);
        $augustE    = strtotime($y . '09-22' . $his);
        // 天秤座
        $septemberS = strtotime($y . '09-23' . $his);
        $septemberE = strtotime($y . '10-23' . $his);
        // 天蝎座
        $octoberS   = strtotime($y . '10-24' . $his);
        $octoberE   = strtotime($y . '11-22' . $his);
        // 射手座
        $novemberS  = strtotime($y . '11-23' . $his);
        $novemberE  = strtotime($y . '12-21' . $his);
    
        if($userTime >= $januaryS && $userTime <= $januaryE){
            $constellation = '水瓶座';
        }elseif($userTime >= $februaryS && $userTime <= $februaryE){
            $constellation = '双鱼座';
        }elseif($userTime >= $marchS && $userTime <= $marchE){
            $constellation = '白羊座';
        }elseif($userTime >= $aprilS && $userTime <= $aprilE){
            $constellation = '金牛座';
        }elseif($userTime >= $mayS && $userTime <= $mayE){
            $constellation = '双子座';
        }elseif($userTime >= $juneS && $userTime <= $juneE){
            $constellation = '巨蟹座';
        }elseif($userTime >= $julyS && $userTime <= $julyE){
            $constellation = '狮子座';
        }elseif($userTime >= $augustS && $userTime <= $augustE){
            $constellation = '处女座';
        }elseif($userTime >= $septemberS && $userTime <= $septemberE){
            $constellation = '天秤座';
        }elseif($userTime >= $octoberS && $userTime <= $octoberE){
            $constellation = '天蝎座';
        }elseif($userTime >= $novemberS && $userTime <= $novemberE){
            $constellation = '射手座';
        }else{
            $constellation = '摩羯座';
        }
        return $constellation;
    }
    
    /**
     * 根据生日算年龄
     * @param $birthday
     * @return false|string
     */
    public function getAge($birthday){
        $time = strtotime($birthday);//取得生日的时间戳
        $byear = date('Y', $time);//生日时间--年
        $bmonth = date('m', $time);//生日时间--月
        $bday = date('d', $time);//生日时间--日
        //初始化当前日期
        $nyear = date('Y');
        $nmonth = date('m');
        $nday = date('d');
        //计算年龄
        $age = $nyear - $byear;
        //如果当前时间的month小于生日的month，则年龄-1岁
        if($nmonth < $bmonth){
            $age = $age - 1;
            //如果当前时间的month等于生日的month，并且当前时间的day小于生日的day，则年龄-1
        }elseif($nmonth == $bmonth && $nday < $bday){
            $age = $age - 1;
        }
        return $age;
    }

    /***
     * @param $user_id
     * @return int
     * 获取男性Vip等级
     */
    public function getVip($user_id){
        $user_consume =Db::table('up_u_user')->where('user_id',$user_id)->value('user_consume');
        $other_recharge_prop = Db::table('up_other')->where('other_id',7)->value('other_recharge_prop');
        $vip = ($user_consume/$other_recharge_prop)/1000;
        if($vip>1){
            $user_vip = intval($vip);
        }else{
            $user_vip = 1;
        }
        return $user_vip;
    }

    /**
     * 获取七牛token
     * @return string
     */
    public function getQiniuToken(){//echo 1;die;
        require_once ('../extend/qiniu/autoload.php');
        header("Access-Control-Allow-Origin:*");
        $accessKey = config('qiniu')['accessKey'];
        $secretKey = config('qiniu')['secretKey'];
        $bucket = config('qiniu')['bucket'];
//        $auth = new Qiniu();
        $auth = new Auth($accessKey, $secretKey);
        $token = $auth->uploadToken($bucket);
        return json_encode(array('data'=>$token));
    }

    /**
     * 首字母
     * @param $str
     * @return string
     */
    public function Getzimu($str)
    {
        if(empty($str)){
            return '#';
        }
        $fchar = mb_substr($str, 0, 1, 'utf-8');
        // 判断表情    表情长度为4位
        if(strlen($fchar) >= 4 ){
            return '#';
        }
//        print_r(ord('z'));die;
//        $fchar=ord($str{0});
        if(ord($fchar) >= ord('A') && ord($fchar) <= ord('z')){
            return strtoupper($fchar);
        }
        $s1 = iconv('UTF-8', 'gb2312', $str);
        $s2 = iconv('gb2312', 'UTF-8', $s1);
        $s = $s2 == $str ? $s1 : $str;
        $asc = ord($s{0})*256+ord($s{1})-65536;
        if($asc >= -20319 && $asc <= -20284) return 'A';
        if($asc >= -20283 && $asc <= -19776) return 'B';
        if($asc >= -19775 && $asc <= -19219) return 'C';
        if($asc >= -19218 && $asc <= -18711) return 'D';
        if($asc >= -18710 && $asc <= -18527) return 'E';
        if($asc >= -18526 && $asc <= -18240) return 'F';
        if($asc >= -18239 && $asc <= -17923) return 'G';
        if($asc >= -17922 && $asc <= -17418) return 'H';
        if($asc >= -17417 && $asc <= -16475) return 'J';
        if($asc >= -16474 && $asc <= -16213) return 'K';
        if($asc >= -16212 && $asc <= -15641) return 'L';
        if($asc >= -15640 && $asc <= -15166) return 'M';
        if($asc >= -15165 && $asc <= -14923) return 'N';
        if($asc >= -14922 && $asc <= -14915) return 'O';
        if($asc >= -14914 && $asc <= -14631) return 'P';
        if($asc >= -14630 && $asc <= -14150) return 'Q';
        if($asc >= -14149 && $asc <= -14091) return 'R';
        if($asc >= -14090 && $asc <= -13319) return 'S';
        if($asc >= -13318 && $asc <= -12839) return 'T';
        if($asc >= -12838 && $asc <= -12557) return 'W';
        if($asc >= -12556 && $asc <= -11848) return 'X';
        if($asc >= -11847 && $asc <= -11056) return 'Y';
        if($asc >= -11055 && $asc <= -10247) return 'Z';
        return "#";
    }
    public function getCityAndHot($city)
    {
        $data = array();
        foreach ($city as $k=>$v){
            $str = $v['name'];
            $str= iconv("UTF-8","gb2312", $str);
            $tmp=bin2hex(substr($str,0,1));
            if($tmp>='B0'){ //汉字的开始
                $t=$this->getLetter(hexdec(bin2hex(substr($str,0,2))));
                $letter = chr($t);
                $data[$k]['id'] = $v['friend_id'];
                $data[$k]['name'] = $v['name'];
                $data[$k]['letter'] = $letter;
                $data[$k]['vip'] = $v['vip'];
                $data[$k]['user_id'] = $v['user_id'];
                $data[$k]['other_user_id'] = $v['other_user_id'];
                $data[$k]['user_image'] = $v['user_image'];

            }
        }
        $last_names = array_column($data,'letter');
        array_multisort($last_names,SORT_ASC,$data);
        $start = '';
        $res = array();
        foreach ($data as $k=>$v){
            if($v['letter'] != $start){
                $start = $v['letter'];
            }
            $res[$start][] = $v;
        }
        return $res;
    }
    public function getLetter($num){
        $limit = array( //gb2312 拼音排序
            array(45217,45252), //A
            array(45253,45760), //B
            array(45761,46317), //C
            array(46318,46825), //D
            array(46826,47009), //E
            array(47010,47296), //F
            array(47297,47613), //G
            array(47614,48118), //H
            array(0,0),     //I
            array(48119,49061), //J
            array(49062,49323), //K
            array(49324,49895), //L
            array(49896,50370), //M
            array(50371,50613), //N
            array(50614,50621), //O
            array(50622,50905), //P
            array(50906,51386), //Q
            array(51387,51445), //R
            array(51446,52217), //S
            array(52218,52697), //T
            array(0,0),     //U
            array(0,0),     //V
            array(52698,52979), //W
            array(52980,53688), //X
            array(53689,54480), //Y
            array(54481,55289), //Z
        );
        $char_index=65;
        foreach($limit as $k=>$v){
            if($num>=$v[0] && $num<=$v[1]){
                $char_index+=$k;
                return $char_index;
            }
        }
        return -1;
    }
    //获取融云token
    public function rongyun($uid,$name,$imageurl){
        $appKey = config('rong.appKey');
        $appSecret = config('rong.appSecret');
        $uid = strval($uid);
        $body = "userId={$uid}&name={$name}&portraitUri={$imageurl}";
        $nonce = mt_rand();
        $timeStamp = time();
        $sign = sha1($appSecret.$nonce.$timeStamp);
        $header = array(
            'App-Key:'.$appKey,
            'Nonce:'.$nonce,
            'Timestamp:'.$timeStamp,
            'Signature:'.$sign,
            'Content-Type: application/x-www-form-urlencoded'
        );
        $url = 'http://api.cn.ronghub.com/user/getToken.json';
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch,CURLOPT_POST,1);
        curl_setopt($ch,CURLOPT_POSTFIELDS,$body);
//    curl_setopt($ch, CURLOPT_SSL_VERI/FYPEER, false);
//    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        $result = curl_exec($ch);
        curl_close($ch);
        $res = json_decode($result,true);
        return $res;
//    var_dump($res) ;
    }
    /**
     * 获取uuid
     * @param string $prefix
     * @return string
     */
    public function uuid($prefix = '')
    {
        $chars = md5(uniqid(mt_rand(), true));
        $uuid  = substr($chars,0,8);
        $uuid .= substr($chars,8,4);
        $uuid .= substr($chars,12,4);
        $uuid .= substr($chars,16,4);
        $uuid .= substr($chars,20,12);
        return $prefix . $uuid;
    }
    //--------------------------------------------------融云群聊的操作------------------------------------------------
    //建群
    public function create($uids,$groupid,$name){
        $appKey = config('rong.appKey');
        $appSecret = config('rong.appSecret');
        $body = "{$uids}groupId=$groupid&groupName=$name";
        $nonce = mt_rand();
        $timeStamp = time();
        $sign = sha1($appSecret . $nonce . $timeStamp);
        $header = array(
            'App-Key:' . $appKey,
            'Nonce:' . $nonce,
            'Timestamp:' . $timeStamp,
            'Signature:' . $sign,
            'Content-Type: application/x-www-form-urlencoded'
        );
        $url = 'http://api.cn.ronghub.com/group/create.json';
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
//    curl_setopt($ch, CURLOPT_SSL_VERI/FYPEER, false);
//    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        $result = curl_exec($ch);
        curl_close($ch);
        $res = json_decode($result, true);
        return $res;
    }

    //加入
    /**
     * @return mixed
     */
    public function joinin($uidstr,$groupid,$name)
    {
        $appKey = config('rong.appKey');
        $appSecret = config('rong.appSecret');
        $body = "{$uidstr}groupId=$groupid&groupName=$name";
        $nonce = mt_rand();
        $timeStamp = time();
        $sign = sha1($appSecret . $nonce . $timeStamp);
        $header = array(
            'App-Key:' . $appKey,
            'Nonce:' . $nonce,
            'Timestamp:' . $timeStamp,
            'Signature:' . $sign,
            'Content-Type: application/x-www-form-urlencoded'
        );
        $url = 'http://api.cn.ronghub.com/group/join.json';
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
//    curl_setopt($ch, CURLOPT_SSL_VERI/FYPEER, false);
//    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        $result = curl_exec($ch);
        curl_close($ch);
        $res = json_decode($result, true);
        return $res;
    }

    //退出
    public function getout($uidstr,$groupid)
    {
        $appKey = config('rong.appKey');
        $appSecret = config('rong.appSecret');
        $body = "{$uidstr}groupId=$groupid";
        $nonce = mt_rand();
        $timeStamp = time();
        $sign = sha1($appSecret . $nonce . $timeStamp);
        $header = array(
            'App-Key:' . $appKey,
            'Nonce:' . $nonce,
            'Timestamp:' . $timeStamp,
            'Signature:' . $sign,
            'Content-Type: application/x-www-form-urlencoded'
        );
        $url = 'http://api.cn.ronghub.com/group/quit.json';
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
//    curl_setopt($ch, CURLOPT_SSL_VERI/FYPEER, false);
//    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        $result = curl_exec($ch);
        curl_close($ch);
        $res = json_decode($result, true);
        return $res;
    }
    //解散
    public function kill($uid,$groupid)
    {
        $appKey = config('rong.appKey');
        $appSecret = config('rong.appSecret');
        $body = "userId=$uid&groupId=$groupid";
        $nonce = mt_rand();
        $timeStamp = time();
        $sign = sha1($appSecret . $nonce . $timeStamp);
        $header = array(
            'App-Key:' . $appKey,
            'Nonce:' . $nonce,
            'Timestamp:' . $timeStamp,
            'Signature:' . $sign,
            'Content-Type: application/x-www-form-urlencoded'
        );
        $url = 'http://api.cn.ronghub.com/group/dismiss.json';
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
//    curl_setopt($ch, CURLOPT_SSL_VERI/FYPEER, false);
//    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        $result = curl_exec($ch);
        curl_close($ch);
        $res = json_decode($result, true);
        return $res;
    }
    //---------------------------mabao--------------------------------


    /**
     * 极光推送--推送消息类型-加盟商
     * @param $type 1:推送个人  2:推送全体
     * @param $alias 别名 user_id OR token
     * @param $message 推送消息内容
     * @param $code
     * @return array
     */
    public function Jpush1($type,$alias,$message,$extras,$code)
    {
//        $alias = (string)$alias;
        import('jpush.autoload', EXTEND_PATH);
        //初始化JPushClient
        $client = new \JPush\Client(config('jpush.appKey'),config('jpush.masterSecret'));
        //生成推送Payload构建器
        $push = $client->push();
        //推送平台 'all'  OR  ['ios','android']  OR  'ios','android'
        $push->setPlatform('all');
        //1:推送个人  2:推送全体
        if($type==1){
            $push->addAlias($alias);//按别名推送
        }else{
            $push->addAllAudience();//广播消息推送
        }
        //IOS推送
        $push->iosNotification($message, [
                'alert'=>$message,
                'badge' => '+1',
                'extras' => $extras,
                'sound'=>'default'
            ]
        );
        //Android推送
        $push->androidNotification($message, [
                'alert'=>$message,
                'extras' => $extras
            ]
        );
        $extras['key'] = $code;
        $push->message($message, [
            'content_type' => 'text',
            'extras' => $extras
        ]);
        return $push->send();
    }
}